package com.zjitc.service.impl;

import com.zjitc.mapper.CartMapper;
import com.zjitc.pojo.AddCart;
import com.zjitc.pojo.Cart;
import com.zjitc.pojo.Product;
import com.zjitc.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CartServiceImpl implements CartService {
    @Autowired
    private CartMapper cartMapper;

    @Override
    public List<Cart> queryCartByUserAll(int u_id) {
        return cartMapper.queryCartByUserAll(u_id);
    }

    @Override
    public void insertCart(Cart cart) {
        if (cartMapper.queryCartById(cart)==null){
            cartMapper.insertCart(cart);
        }else {
            Cart getCart=cartMapper.queryCartById(cart);
            int number = getCart.getC_number();
            getCart.setC_number(++number);
            cartMapper.updateCartById(getCart);
        }
    }

    @Override
    public Cart queryCartById(Cart cart) {
        return cartMapper.queryCartById(cart);
    }

    @Override
    public void deleteCartById(int id) {
        cartMapper.deleteCartById(id);
    }

    @Override
    public void updateCartById(Cart cart) {
        cartMapper.updateCartById(cart);
    }
}
